
TOOL.Category   = "Wire - Display"
TOOL.Name       = "BGP"
TOOL.Command    = nil
TOOL.ConfigName = ""
TOOL.Tab		= "Wire"

if SERVER then
	CreateConVar('sbox_maxwire_BGP', 5)
end

TOOL.model=CreateClientConVar("wire_bgp_model", "models/cheeze/pcb/pcb4.mdl", true, true)

cleanup.Register( "wire BGP" )


if ( CLIENT ) then

	language.Add( "Tool_wire_BGP_name", "Bitmap Graphic Processor" )
	language.Add( "Tool_wire_BGP_desc", "Display Bitmap on screen!" )
	language.Add( "Tool_wire_BGP_0", "Click somewhere to spawn a BGP." )

	language.Add( "Undone_BGP", "Undone BGP" )
	language.Add( "Cleanup_BGP", "Wire BGP" )
	language.Add( "Cleaned_BGP", "Cleaned up all BGPs" )

end

if (SERVER) then

	function TOOL:Create( ply, trace, model )
		if (!trace or !trace.Hit) then return end
		if (!ply:CheckLimit("wire_bgp")) then return end
		local ent = ents.Create("gmod_wire_BGP")
		if (!ent) then return end
		ent:SetModel( model or "models/cheeze/pcb/pcb4.mdl" )
		ent:SetPos( trace.HitPos - trace.HitNormal * ent:OBBMins().z )
		ent:SetAngles( trace.HitNormal:Angle() + Angle(90,0,0) )
		ent:SetPlayer( ply )
		ent:Spawn()
		ent:Activate()
		ply:AddCount( "wire_bgp", ent )
		return ent
	end
	
end

function TOOL:LeftClick( trace )

	if (!trace) then return end
	if (CLIENT) then return true end
	local ply = self:GetOwner()

	local ent = self:Create( ply, trace, self.model:GetString())
	
	if(!ent) then return false end
	
	local const = WireLib.Weld( ent, trace.Entity, trace.PhysicsBone, true )
	undo.Create("wire BGP")
		undo.AddEntity( ent )
		undo.AddEntity( const )
		undo.SetPlayer( ply )
	undo.Finish()

	ply:AddCleanup( "wire BGP", ent )

	return true

end

function TOOL:RightClick( trace )
	return false
end

function TOOL.BuildCPanel( panel )
	
		panel:SetSpacing( 10 )
		panel:SetName( "BGP" )
		
		panel:AddControl( "Label", { Text = "Bitmap Graphic Processor by Fun Maker"}  )
		
		panel:AddControl("Header", { Text = "#Tool_wire_bgp_name", Description = "#Tool_wire_bgp_desc" })
		WireDermaExts.ModelSelect(panel, "wire_bgp_model", list.Get( "WireScreenModels" ), 5)

end
